package com.fbooks.Controller;

import com.alibaba.fastjson.JSONObject;
import com.fbooks.bean.ArticleComment;
import com.fbooks.mapper.ArticleCommentMapper;
import com.fbooks.service.ArticleCommontService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: LuoRunFeng
 * @Email: 475403147@qq.com
 * @Time: 2020/5/28 0028 22:09
 * @Team: 蜂鸟工作室
 */
@Controller
@CrossOrigin
@RequestMapping("commont")
public class CommontController {

    @Autowired
    private ArticleCommontService articleCommontService;

    @RequestMapping("release")
    @ResponseBody
    public JSONObject releaseCommont(@RequestBody ArticleComment articleComment){
        System.out.println(articleComment);
        articleComment.setCreateTime(new Timestamp(System.currentTimeMillis()));
        JSONObject jsonObject = articleCommontService.releaseCommont(articleComment);
        return jsonObject;
    }

    @RequestMapping("get")
    @ResponseBody
    public List<JSONObject> getCommentByUid(@RequestBody JSONObject INFO){
        //获取uid
        String uid = String.valueOf(INFO.get("id"));
        System.out.println(uid);
        List<JSONObject> jsonObjectList = articleCommontService.getCommentByUid(uid);
        return jsonObjectList;
    }
}
